import { Prisma } from '@prisma/client';
import { Transform, Type } from 'class-transformer';
import {
  IsDefined,
  IsNotEmptyObject,
  Max,
  Min,
  ValidateNested,
} from 'class-validator';
import { BaseDto, BaseFindDto, BaseQueryDto, WhiteListItem } from './base.dto';

export class ActivityCreateDto extends BaseDto<Prisma.ActivityCreateInput> {}

export class ActivityUpdateDto extends BaseDto<Prisma.ActivityUpdateInput> {
  @IsDefined({ message: '条件必填' })
  @IsNotEmptyObject({ nullable: false }, { message: '条件参数必填' })
  where: Prisma.ActivityWhereUniqueInput;
}

export class ActivityRemoveDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;
}

export class ActivityFindDto extends BaseFindDto<
  Prisma.ActivityWhereUniqueInput,
  Prisma.ActivitySelect
> {}

export class ActivityQueryDto extends BaseQueryDto<Prisma.ActivityWhereUniqueInput> {}

export class ActivityListDto extends BaseQueryDto<Prisma.ActivityWhereUniqueInput> {}

export class ActivityLoadDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;

  @ValidateNested({ each: true })
  @Type(() => WhiteListItem)
  rows?: WhiteListItem[];
}

export class ActivityOrderDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;

  @IsDefined({ message: '方案ID必填' })
  @Transform(({ value }) => Number(value))
  planId: number;

  @IsDefined({ message: '数量必填' })
  @Transform(({ value }) => Number(value))
  @Min(1, { message: '数量不能小于1' })
  @Max(100, { message: '数量不能大于100' })
  num?: number;
}
